package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.IllInfoService;
import com.lianwei.hospital.mapper.IllInfoMapper;
import com.lianwei.hospital.module.entity.ErInfo;
import com.lianwei.hospital.module.entity.IllInfo;
import com.lianwei.hospital.module.vo.IllVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("IllInfoService")
public class IllInfoImpl implements IllInfoService {
    @Autowired
    IllInfoMapper illInfoMapper;

    @Override
    public IllInfo selectByPrimaryKey(String id) throws Exception {
        return illInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean insert(IllInfo illInfo) throws Exception {
        return illInfoMapper.insert(illInfo)>0;
    }

    @Override
    public List<IllInfo> selectAll() throws Exception {
        return illInfoMapper.selectAll();
    }

    @Override
    public boolean deleteByPrimaryKey(String id) throws Exception {
        return illInfoMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean updateByPrimaryKey(IllInfo illInfo) throws Exception {
        return illInfoMapper.updateByPrimaryKey(illInfo)>0;
    }

    @Override
    public PageUtil<IllInfo> findPage(IllVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=illInfoMapper.countBySelectActive(query);
        if (count>0){
            List<IllInfo> data=illInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
